package com.demo.test;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class ShuZu {
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[] mSz = new int[m];
        int[] nSz = new int[n];
        for (int i = 0; i < m; i++) {
            mSz[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            nSz[i] = sc.nextInt();
        }
        int count = 0;
//        for (int i = 0; i < m; i++) {
//            for (int j = 0; j < n; j++) {
//                if (mSz[i] == nSz[j]) {
//                    count++;
//                }
//            }
//        }


        System.out.println(count);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[] mSz = new int[m];
        int[] nSz = new int[n];
        for (int i = 0; i < m; i++) {
            mSz[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            nSz[i] = sc.nextInt();
        }
        int count = 0;
        int[] lSz = m > n ? mSz : nSz;
        int[] sSz = m > n ? nSz : mSz;
        Map<Integer, Integer> map = new HashMap<>(m);

        for (int i = 0; i < lSz.length; i++) {
            map.put(lSz[i], map.getOrDefault(lSz[i], 0) + 1);
        }

        for (int i = 0; i < sSz.length; i++) {
            count += map.getOrDefault(sSz[i],0);
        }
        System.out.println(count);
    }
}
